Passed
Branch master (0c09a6)
by Stephan
01:45
created

modal.js ➔ ... ➔ Modal.constructor   B

Complexity

Conditions 1
Paths > 20000

Size

Total Lines 466
Code Lines 267

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 267
nc 196608
nop 0
dl 0
loc 466
rs 7
c 1
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
/*!
2
  * Bootstrap modal.js v4.3.1 (https://getbootstrap.com/)
3
  * Copyright 2011-2019 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
4
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
5
  */
6
(function (global, factory) {
7
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('./util.js')) :
8
  typeof define === 'function' && define.amd ? define(['jquery', './util.js'], factory) :
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
9
  (global = global || self, global.Modal = factory(global.jQuery, global.Util));
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable self is declared in the current environment, consider using typeof self === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10
}(this, function ($, Util) { 'use strict';
11
12
  $ = $ && $.hasOwnProperty('default') ? $['default'] : $;
13
  Util = Util && Util.hasOwnProperty('default') ? Util['default'] : Util;
14
15
  function _defineProperties(target, props) {
16
    for (var i = 0; i < props.length; i++) {
17
      var descriptor = props[i];
18
      descriptor.enumerable = descriptor.enumerable || false;
19
      descriptor.configurable = true;
20
      if ("value" in descriptor) descriptor.writable = true;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
21
      Object.defineProperty(target, descriptor.key, descriptor);
22
    }
23
  }
24
25
  function _createClass(Constructor, protoProps, staticProps) {
26
    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
27
    if (staticProps) _defineProperties(Constructor, staticProps);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
28
    return Constructor;
29
  }
30
31
  function _defineProperty(obj, key, value) {
32
    if (key in obj) {
33
      Object.defineProperty(obj, key, {
34
        value: value,
35
        enumerable: true,
36
        configurable: true,
37
        writable: true
38
      });
39
    } else {
40
      obj[key] = value;
41
    }
42
43
    return obj;
44
  }
45
46 View Code Duplication
  function _objectSpread(target) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
47
    for (var i = 1; i < arguments.length; i++) {
48
      var source = arguments[i] != null ? arguments[i] : {};
0 ignored issues
show
Best Practice introduced by
Comparing arguments.i to null using the != operator is not safe. Consider using !== instead.
Loading history...
49
      var ownKeys = Object.keys(source);
50
51
      if (typeof Object.getOwnPropertySymbols === 'function') {
52
        ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
53
          return Object.getOwnPropertyDescriptor(source, sym).enumerable;
0 ignored issues
show
Bug introduced by
The variable source is changed as part of the for loop for example by arguments.i != null ? arguments.i: {} on line 48. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
54
        }));
55
      }
56
57
      ownKeys.forEach(function (key) {
58
        _defineProperty(target, key, source[key]);
0 ignored issues
show
Bug introduced by
The variable source is changed as part of the for loop for example by arguments.i != null ? arguments.i: {} on line 48. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
59
      });
60
    }
61
62
    return target;
63
  }
64
65
  /**
66
   * ------------------------------------------------------------------------
67
   * Constants
68
   * ------------------------------------------------------------------------
69
   */
70
71
  var NAME = 'modal';
72
  var VERSION = '4.3.1';
73
  var DATA_KEY = 'bs.modal';
74
  var EVENT_KEY = "." + DATA_KEY;
75
  var DATA_API_KEY = '.data-api';
76
  var JQUERY_NO_CONFLICT = $.fn[NAME];
77
  var ESCAPE_KEYCODE = 27; // KeyboardEvent.which value for Escape (Esc) key
78
79
  var Default = {
80
    backdrop: true,
81
    keyboard: true,
82
    focus: true,
83
    show: true
84
  };
85
  var DefaultType = {
86
    backdrop: '(boolean|string)',
87
    keyboard: 'boolean',
88
    focus: 'boolean',
89
    show: 'boolean'
90
  };
91
  var Event = {
92
    HIDE: "hide" + EVENT_KEY,
93
    HIDDEN: "hidden" + EVENT_KEY,
94
    SHOW: "show" + EVENT_KEY,
95
    SHOWN: "shown" + EVENT_KEY,
96
    FOCUSIN: "focusin" + EVENT_KEY,
97
    RESIZE: "resize" + EVENT_KEY,
98
    CLICK_DISMISS: "click.dismiss" + EVENT_KEY,
99
    KEYDOWN_DISMISS: "keydown.dismiss" + EVENT_KEY,
100
    MOUSEUP_DISMISS: "mouseup.dismiss" + EVENT_KEY,
101
    MOUSEDOWN_DISMISS: "mousedown.dismiss" + EVENT_KEY,
102
    CLICK_DATA_API: "click" + EVENT_KEY + DATA_API_KEY
103
  };
104
  var ClassName = {
105
    SCROLLABLE: 'modal-dialog-scrollable',
106
    SCROLLBAR_MEASURER: 'modal-scrollbar-measure',
107
    BACKDROP: 'modal-backdrop',
108
    OPEN: 'modal-open',
109
    FADE: 'fade',
110
    SHOW: 'show'
111
  };
112
  var Selector = {
113
    DIALOG: '.modal-dialog',
114
    MODAL_BODY: '.modal-body',
115
    DATA_TOGGLE: '[data-toggle="modal"]',
116
    DATA_DISMISS: '[data-dismiss="modal"]',
117
    FIXED_CONTENT: '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top',
118
    STICKY_CONTENT: '.sticky-top'
119
    /**
120
     * ------------------------------------------------------------------------
121
     * Class Definition
122
     * ------------------------------------------------------------------------
123
     */
124
125
  };
126
127
  var Modal =
128
  /*#__PURE__*/
129
  function () {
130
    function Modal(element, config) {
131
      this._config = this._getConfig(config);
132
      this._element = element;
133
      this._dialog = element.querySelector(Selector.DIALOG);
134
      this._backdrop = null;
135
      this._isShown = false;
136
      this._isBodyOverflowing = false;
137
      this._ignoreBackdropClick = false;
138
      this._isTransitioning = false;
139
      this._scrollbarWidth = 0;
140
    } // Getters
141
142
143
    var _proto = Modal.prototype;
144
145
    // Public
146
    _proto.toggle = function toggle(relatedTarget) {
147
      return this._isShown ? this.hide() : this.show(relatedTarget);
148
    };
149
150
    _proto.show = function show(relatedTarget) {
151
      var _this = this;
152
153
      if (this._isShown || this._isTransitioning) {
154
        return;
155
      }
156
157
      if ($(this._element).hasClass(ClassName.FADE)) {
158
        this._isTransitioning = true;
159
      }
160
161
      var showEvent = $.Event(Event.SHOW, {
162
        relatedTarget: relatedTarget
163
      });
164
      $(this._element).trigger(showEvent);
165
166
      if (this._isShown || showEvent.isDefaultPrevented()) {
167
        return;
168
      }
169
170
      this._isShown = true;
171
172
      this._checkScrollbar();
173
174
      this._setScrollbar();
175
176
      this._adjustDialog();
177
178
      this._setEscapeEvent();
179
180
      this._setResizeEvent();
181
182
      $(this._element).on(Event.CLICK_DISMISS, Selector.DATA_DISMISS, function (event) {
183
        return _this.hide(event);
184
      });
185
      $(this._dialog).on(Event.MOUSEDOWN_DISMISS, function () {
186
        $(_this._element).one(Event.MOUSEUP_DISMISS, function (event) {
187
          if ($(event.target).is(_this._element)) {
188
            _this._ignoreBackdropClick = true;
189
          }
190
        });
191
      });
192
193
      this._showBackdrop(function () {
194
        return _this._showElement(relatedTarget);
195
      });
196
    };
197
198
    _proto.hide = function hide(event) {
199
      var _this2 = this;
200
201
      if (event) {
202
        event.preventDefault();
203
      }
204
205
      if (!this._isShown || this._isTransitioning) {
206
        return;
207
      }
208
209
      var hideEvent = $.Event(Event.HIDE);
210
      $(this._element).trigger(hideEvent);
211
212
      if (!this._isShown || hideEvent.isDefaultPrevented()) {
213
        return;
214
      }
215
216
      this._isShown = false;
217
      var transition = $(this._element).hasClass(ClassName.FADE);
218
219
      if (transition) {
220
        this._isTransitioning = true;
221
      }
222
223
      this._setEscapeEvent();
224
225
      this._setResizeEvent();
226
227
      $(document).off(Event.FOCUSIN);
228
      $(this._element).removeClass(ClassName.SHOW);
229
      $(this._element).off(Event.CLICK_DISMISS);
230
      $(this._dialog).off(Event.MOUSEDOWN_DISMISS);
231
232
      if (transition) {
233
        var transitionDuration = Util.getTransitionDurationFromElement(this._element);
234
        $(this._element).one(Util.TRANSITION_END, function (event) {
235
          return _this2._hideModal(event);
236
        }).emulateTransitionEnd(transitionDuration);
237
      } else {
238
        this._hideModal();
239
      }
240
    };
241
242
    _proto.dispose = function dispose() {
243
      [window, this._element, this._dialog].forEach(function (htmlElement) {
244
        return $(htmlElement).off(EVENT_KEY);
245
      });
246
      /**
247
       * `document` has 2 events `Event.FOCUSIN` and `Event.CLICK_DATA_API`
248
       * Do not move `document` in `htmlElements` array
249
       * It will remove `Event.CLICK_DATA_API` event that should remain
250
       */
251
252
      $(document).off(Event.FOCUSIN);
253
      $.removeData(this._element, DATA_KEY);
254
      this._config = null;
255
      this._element = null;
256
      this._dialog = null;
257
      this._backdrop = null;
258
      this._isShown = null;
259
      this._isBodyOverflowing = null;
260
      this._ignoreBackdropClick = null;
261
      this._isTransitioning = null;
262
      this._scrollbarWidth = null;
263
    };
264
265
    _proto.handleUpdate = function handleUpdate() {
266
      this._adjustDialog();
267
    } // Private
268
    ;
269
270
    _proto._getConfig = function _getConfig(config) {
271
      config = _objectSpread({}, Default, config);
272
      Util.typeCheckConfig(NAME, config, DefaultType);
273
      return config;
274
    };
275
276
    _proto._showElement = function _showElement(relatedTarget) {
277
      var _this3 = this;
278
279
      var transition = $(this._element).hasClass(ClassName.FADE);
280
281
      if (!this._element.parentNode || this._element.parentNode.nodeType !== Node.ELEMENT_NODE) {
0 ignored issues
show
Bug introduced by
The variable Node seems to be never declared. If this is a global, consider adding a /** global: Node */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
282
        // Don't move modal's DOM position
283
        document.body.appendChild(this._element);
284
      }
285
286
      this._element.style.display = 'block';
287
288
      this._element.removeAttribute('aria-hidden');
289
290
      this._element.setAttribute('aria-modal', true);
291
292
      if ($(this._dialog).hasClass(ClassName.SCROLLABLE)) {
293
        this._dialog.querySelector(Selector.MODAL_BODY).scrollTop = 0;
294
      } else {
295
        this._element.scrollTop = 0;
296
      }
297
298
      if (transition) {
299
        Util.reflow(this._element);
300
      }
301
302
      $(this._element).addClass(ClassName.SHOW);
303
304
      if (this._config.focus) {
305
        this._enforceFocus();
306
      }
307
308
      var shownEvent = $.Event(Event.SHOWN, {
309
        relatedTarget: relatedTarget
310
      });
311
312
      var transitionComplete = function transitionComplete() {
313
        if (_this3._config.focus) {
314
          _this3._element.focus();
315
        }
316
317
        _this3._isTransitioning = false;
318
        $(_this3._element).trigger(shownEvent);
319
      };
320
321
      if (transition) {
322
        var transitionDuration = Util.getTransitionDurationFromElement(this._dialog);
323
        $(this._dialog).one(Util.TRANSITION_END, transitionComplete).emulateTransitionEnd(transitionDuration);
324
      } else {
325
        transitionComplete();
326
      }
327
    };
328
329
    _proto._enforceFocus = function _enforceFocus() {
330
      var _this4 = this;
331
332
      $(document).off(Event.FOCUSIN) // Guard against infinite focus loop
333
      .on(Event.FOCUSIN, function (event) {
334
        if (document !== event.target && _this4._element !== event.target && $(_this4._element).has(event.target).length === 0) {
335
          _this4._element.focus();
336
        }
337
      });
338
    };
339
340
    _proto._setEscapeEvent = function _setEscapeEvent() {
341
      var _this5 = this;
342
343
      if (this._isShown && this._config.keyboard) {
344
        $(this._element).on(Event.KEYDOWN_DISMISS, function (event) {
345
          if (event.which === ESCAPE_KEYCODE) {
346
            event.preventDefault();
347
348
            _this5.hide();
349
          }
350
        });
351
      } else if (!this._isShown) {
352
        $(this._element).off(Event.KEYDOWN_DISMISS);
353
      }
354
    };
355
356
    _proto._setResizeEvent = function _setResizeEvent() {
357
      var _this6 = this;
358
359
      if (this._isShown) {
360
        $(window).on(Event.RESIZE, function (event) {
361
          return _this6.handleUpdate(event);
362
        });
363
      } else {
364
        $(window).off(Event.RESIZE);
365
      }
366
    };
367
368
    _proto._hideModal = function _hideModal() {
369
      var _this7 = this;
370
371
      this._element.style.display = 'none';
372
373
      this._element.setAttribute('aria-hidden', true);
374
375
      this._element.removeAttribute('aria-modal');
376
377
      this._isTransitioning = false;
378
379
      this._showBackdrop(function () {
380
        $(document.body).removeClass(ClassName.OPEN);
381
382
        _this7._resetAdjustments();
383
384
        _this7._resetScrollbar();
385
386
        $(_this7._element).trigger(Event.HIDDEN);
387
      });
388
    };
389
390
    _proto._removeBackdrop = function _removeBackdrop() {
391
      if (this._backdrop) {
392
        $(this._backdrop).remove();
393
        this._backdrop = null;
394
      }
395
    };
396
397
    _proto._showBackdrop = function _showBackdrop(callback) {
398
      var _this8 = this;
399
400
      var animate = $(this._element).hasClass(ClassName.FADE) ? ClassName.FADE : '';
401
402
      if (this._isShown && this._config.backdrop) {
403
        this._backdrop = document.createElement('div');
404
        this._backdrop.className = ClassName.BACKDROP;
405
406
        if (animate) {
407
          this._backdrop.classList.add(animate);
408
        }
409
410
        $(this._backdrop).appendTo(document.body);
411
        $(this._element).on(Event.CLICK_DISMISS, function (event) {
412
          if (_this8._ignoreBackdropClick) {
413
            _this8._ignoreBackdropClick = false;
414
            return;
415
          }
416
417
          if (event.target !== event.currentTarget) {
418
            return;
419
          }
420
421
          if (_this8._config.backdrop === 'static') {
422
            _this8._element.focus();
423
          } else {
424
            _this8.hide();
425
          }
426
        });
427
428
        if (animate) {
429
          Util.reflow(this._backdrop);
430
        }
431
432
        $(this._backdrop).addClass(ClassName.SHOW);
433
434
        if (!callback) {
435
          return;
436
        }
437
438
        if (!animate) {
439
          callback();
440
          return;
441
        }
442
443
        var backdropTransitionDuration = Util.getTransitionDurationFromElement(this._backdrop);
444
        $(this._backdrop).one(Util.TRANSITION_END, callback).emulateTransitionEnd(backdropTransitionDuration);
445
      } else if (!this._isShown && this._backdrop) {
446
        $(this._backdrop).removeClass(ClassName.SHOW);
447
448
        var callbackRemove = function callbackRemove() {
449
          _this8._removeBackdrop();
450
451
          if (callback) {
452
            callback();
453
          }
454
        };
455
456
        if ($(this._element).hasClass(ClassName.FADE)) {
457
          var _backdropTransitionDuration = Util.getTransitionDurationFromElement(this._backdrop);
458
459
          $(this._backdrop).one(Util.TRANSITION_END, callbackRemove).emulateTransitionEnd(_backdropTransitionDuration);
460
        } else {
461
          callbackRemove();
462
        }
463
      } else if (callback) {
464
        callback();
465
      }
466
    } // ----------------------------------------------------------------------
467
    // the following methods are used to handle overflowing modals
468
    // todo (fat): these should probably be refactored out of modal.js
469
    // ----------------------------------------------------------------------
470
    ;
471
472
    _proto._adjustDialog = function _adjustDialog() {
473
      var isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;
474
475
      if (!this._isBodyOverflowing && isModalOverflowing) {
476
        this._element.style.paddingLeft = this._scrollbarWidth + "px";
477
      }
478
479
      if (this._isBodyOverflowing && !isModalOverflowing) {
480
        this._element.style.paddingRight = this._scrollbarWidth + "px";
481
      }
482
    };
483
484
    _proto._resetAdjustments = function _resetAdjustments() {
485
      this._element.style.paddingLeft = '';
486
      this._element.style.paddingRight = '';
487
    };
488
489
    _proto._checkScrollbar = function _checkScrollbar() {
490
      var rect = document.body.getBoundingClientRect();
491
      this._isBodyOverflowing = rect.left + rect.right < window.innerWidth;
492
      this._scrollbarWidth = this._getScrollbarWidth();
493
    };
494
495
    _proto._setScrollbar = function _setScrollbar() {
496
      var _this9 = this;
497
498
      if (this._isBodyOverflowing) {
499
        // Note: DOMNode.style.paddingRight returns the actual value or '' if not set
500
        //   while $(DOMNode).css('padding-right') returns the calculated value or 0 if not set
501
        var fixedContent = [].slice.call(document.querySelectorAll(Selector.FIXED_CONTENT));
502
        var stickyContent = [].slice.call(document.querySelectorAll(Selector.STICKY_CONTENT)); // Adjust fixed content padding
503
504
        $(fixedContent).each(function (index, element) {
505
          var actualPadding = element.style.paddingRight;
506
          var calculatedPadding = $(element).css('padding-right');
507
          $(element).data('padding-right', actualPadding).css('padding-right', parseFloat(calculatedPadding) + _this9._scrollbarWidth + "px");
508
        }); // Adjust sticky content margin
509
510
        $(stickyContent).each(function (index, element) {
511
          var actualMargin = element.style.marginRight;
512
          var calculatedMargin = $(element).css('margin-right');
513
          $(element).data('margin-right', actualMargin).css('margin-right', parseFloat(calculatedMargin) - _this9._scrollbarWidth + "px");
514
        }); // Adjust body padding
515
516
        var actualPadding = document.body.style.paddingRight;
517
        var calculatedPadding = $(document.body).css('padding-right');
518
        $(document.body).data('padding-right', actualPadding).css('padding-right', parseFloat(calculatedPadding) + this._scrollbarWidth + "px");
519
      }
520
521
      $(document.body).addClass(ClassName.OPEN);
522
    };
523
524
    _proto._resetScrollbar = function _resetScrollbar() {
525
      // Restore fixed content padding
526
      var fixedContent = [].slice.call(document.querySelectorAll(Selector.FIXED_CONTENT));
527
      $(fixedContent).each(function (index, element) {
528
        var padding = $(element).data('padding-right');
529
        $(element).removeData('padding-right');
530
        element.style.paddingRight = padding ? padding : '';
531
      }); // Restore sticky content
532
533
      var elements = [].slice.call(document.querySelectorAll("" + Selector.STICKY_CONTENT));
534
      $(elements).each(function (index, element) {
535
        var margin = $(element).data('margin-right');
536
537
        if (typeof margin !== 'undefined') {
538
          $(element).css('margin-right', margin).removeData('margin-right');
539
        }
540
      }); // Restore body padding
541
542
      var padding = $(document.body).data('padding-right');
543
      $(document.body).removeData('padding-right');
544
      document.body.style.paddingRight = padding ? padding : '';
545
    };
546
547
    _proto._getScrollbarWidth = function _getScrollbarWidth() {
548
      // thx d.walsh
549
      var scrollDiv = document.createElement('div');
550
      scrollDiv.className = ClassName.SCROLLBAR_MEASURER;
551
      document.body.appendChild(scrollDiv);
552
      var scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth;
553
      document.body.removeChild(scrollDiv);
554
      return scrollbarWidth;
555
    } // Static
556
    ;
557
558
    Modal._jQueryInterface = function _jQueryInterface(config, relatedTarget) {
559
      return this.each(function () {
560
        var data = $(this).data(DATA_KEY);
561
562
        var _config = _objectSpread({}, Default, $(this).data(), typeof config === 'object' && config ? config : {});
563
564
        if (!data) {
565
          data = new Modal(this, _config);
566
          $(this).data(DATA_KEY, data);
567
        }
568
569
        if (typeof config === 'string') {
570
          if (typeof data[config] === 'undefined') {
571
            throw new TypeError("No method named \"" + config + "\"");
572
          }
573
574
          data[config](relatedTarget);
575
        } else if (_config.show) {
576
          data.show(relatedTarget);
577
        }
578
      });
579
    };
580
581
    _createClass(Modal, null, [{
582
      key: "VERSION",
583
      get: function get() {
584
        return VERSION;
585
      }
586
    }, {
587
      key: "Default",
588
      get: function get() {
589
        return Default;
590
      }
591
    }]);
592
593
    return Modal;
594
  }();
595
  /**
596
   * ------------------------------------------------------------------------
597
   * Data Api implementation
598
   * ------------------------------------------------------------------------
599
   */
600
601
602
  $(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
603
    var _this10 = this;
604
605
    var target;
606
    var selector = Util.getSelectorFromElement(this);
607
608
    if (selector) {
609
      target = document.querySelector(selector);
610
    }
611
612
    var config = $(target).data(DATA_KEY) ? 'toggle' : _objectSpread({}, $(target).data(), $(this).data());
0 ignored issues
show
Bug introduced by
The variable target does not seem to be initialized in case selector on line 608 is false. Are you sure the function $ handles undefined variables?
Loading history...
613
614
    if (this.tagName === 'A' || this.tagName === 'AREA') {
615
      event.preventDefault();
616
    }
617
618
    var $target = $(target).one(Event.SHOW, function (showEvent) {
619
      if (showEvent.isDefaultPrevented()) {
620
        // Only register focus restorer if modal will actually get shown
621
        return;
622
      }
623
624
      $target.one(Event.HIDDEN, function () {
625
        if ($(_this10).is(':visible')) {
626
          _this10.focus();
627
        }
628
      });
629
    });
630
631
    Modal._jQueryInterface.call($(target), config, this);
632
  });
633
  /**
634
   * ------------------------------------------------------------------------
635
   * jQuery
636
   * ------------------------------------------------------------------------
637
   */
638
639
  $.fn[NAME] = Modal._jQueryInterface;
640
  $.fn[NAME].Constructor = Modal;
641
642
  $.fn[NAME].noConflict = function () {
643
    $.fn[NAME] = JQUERY_NO_CONFLICT;
644
    return Modal._jQueryInterface;
645
  };
646
647
  return Modal;
648
649
}));
650
//# sourceMappingURL=modal.js.map
651